// Copyright (c) 2009 Mike Haight, Andy Kipp
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#pragma once

#include "stdafx.h"

#include "Input.h"
#include "Renderer.h"
#include "Timer.h"
#include "Window.h"
#include "Scene.h"

namespace HandBanana { namespace Core
{
    using namespace HandBanana::Utilities;
    using namespace HandBanana::Game;

    /// <summary>
    /// 
    /// </summary>
    class Engine
    {
    // Constructor
    public:
        /// <summary>
        ///
        /// </summary>
        Engine(void);


    // Public Properties
    public:
        /// <summary>
        /// 
        /// </summary>
        DECLARE_PROPERTY_GET(GetRenderer, boost::shared_ptr<Renderer>);

        /// <summary>
        /// 
        /// </summary>
        DECLARE_PROPERTY_GET(GetScene, boost::shared_ptr<Scene>);


    // Public Methods
    public:
        /// <summary>
        /// 
        /// </summary>
        void Start(void);

        /// <summary>
        /// 
        /// </summary>
        void Stop(void);


    // Private Methods
    private:
        /// <summary>
        /// 
        /// </summary>
        void Run(void);

        /// <summary>
        /// 
        /// </summary>
        void Load(void);

        /// <summary>
        ///
        /// </summary>
        void Update(void);

        /// <summary>
        ///
        /// </summary>
        void Render(void);

        void WindowActivated(Object& argSender, EventArgs& e);

        void WindowClosed(Object& argSender, EventArgs& e);

        void WindowDeactivated(Object& argSender, EventArgs& e);

        void WindowKillFocus(Object& argSender, EventArgs& e);

        void WindowMinimized(Object& argSender, EventArgs& e);

        void WindowMoved(Object& argSender, MoveEventArgs& e);

        void WindowRestored(Object& argSender, EventArgs& e);

        void WindowSetFocus(Object& argSender, EventArgs& e);

        void WindowSized(Object& argSender, SizeEventArgs& e);


    // Private Data Members
    private:
        // Game Window
        boost::shared_ptr<Window>        mMainWindow;

        // Engine State
        boost::shared_ptr<Renderer>      mRenderer;
        boost::shared_ptr<boost::thread> mEngineThread;
        boost::shared_ptr<boost::thread> mLoadThread;
        boost::shared_ptr<Input>         mInput;
        boost::shared_ptr<Timer>         mTimer;

        bool                             mStallRendering;
        bool                             mRunning;
        bool                             mLoading;

        // View State
        Rectangle                        mWorldView;
        Rectangle                        mUIView;

        // Game State
        boost::shared_ptr<Scene>         mScene;
        //static World^                               smWorld;
        //static Player^                              smPlayer;
        //static ParticleSystem<SmokeParticle^>^      smSmokeParticleSystem;
        //static ParticleSystem<FireParticle^>^       smFireParticleSystem;
        //static ParticleSystem<AuraParticle^>^       smAuraParticleSystem;

        // UI State
        //static LoadingBar^                          smLoadingBar;
        //static UI^                                  smUserInterface;


    public:
        bool QuitFlag;

    };
} }